<?php

namespace  Api\Controller;
use Com\Easemob;

class HxController extends ApiController{    
  
   public function getusers(){   
       $hx=new Easemob();
      response(1, $hx->getUsers());   
   }
   
   /**
    * 新增用户
    * @param string $username
    */
   public function createUser(){
      $username=I('username');
      $password='123456';
      empty($username) &&  response(-2,'','用户名不能为空');
      $hx=new Easemob();
      $result=$hx->createUser($username, $password);
      echo $result;
   }
   
   public function createusers(){
       
       $users=M('ucenter_member')->field('username')->select();
       $options=array();
       
       foreach($users as $value){
           //$options[]=array('username'=>$value['username'],'password'=>'123456');
       }
       
       //response(1,$options);
       $hx=new Easemob();
       
       //已经注册用户
       $hx_users=$hx->getUsers(50)['entities'];
       $hx_valuser=array();
       foreach ($hx_users as $item){
           $hx_valuser[]=$item['username'];
       }
       
       foreach ($users as $item){
           if(!in_array($item['username'], $hx_valuser)){
               $options[]=array('username'=>$item['username'],'password'=>'123456');
           }
       }
       //延迟一秒 防止服务器进黑名单
      sleep(1);
      //$result=$hx->createUsers($options);
      response(1,$options);
   }
   
}